﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace DAC.Simulator
{
    public class SimulatorLogger : ILogInterface
    {
        private TextBoxBase _outputObj;
        private string _prefix;
        private Color _foreColor;
        private bool _isRichText;


        public SimulatorLogger(RichTextBox outputObj, string prefix, Color foreColor)
        {
            _foreColor = foreColor;
            _outputObj = outputObj;
            _isRichText = true;
            _prefix = prefix;
        }

        public void Write(string message)
        {
            InternalWrite(message);
        }

        public void WriteLine(string message)
        {
            InternalWriteLine(message);
        }
        private void InternalWriteLine(string message)
        {
            InternalWrite(message);
            _outputObj.AppendText(Environment.NewLine);
            _outputObj.ScrollToCaret();
        }

        private void InternalWrite(string message)
        {
            _outputObj.Select(_outputObj.Text.Length, 0);
            if (_isRichText) ((RichTextBox)_outputObj).SelectionColor = _foreColor;
            _outputObj.AppendText(_prefix);
            _outputObj.AppendText(" : ");
            _outputObj.AppendText(message);
            _outputObj.ScrollToCaret();
        }

    }
}
